/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bionic.ce.entities;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 *
 * @author Jarik
 */
@Entity
@Table(name = "systemacc")
@NamedQueries({
    @NamedQuery(name = "Systemacc.findAll", query = "SELECT s FROM Systemacc s"),
    @NamedQuery(name = "Systemacc.findByAccNum", query = "SELECT s FROM Systemacc s WHERE s.accNum = :accNum"),
    @NamedQuery(name = "Systemacc.findByAmount", query = "SELECT s FROM Systemacc s WHERE s.amount = :amount"),
    @NamedQuery(name = "Systemacc.findByStatus", query = "SELECT s FROM Systemacc s WHERE s.status = :status")})
public class Systemacc implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "AccNum")
    private Integer accNum;
    @Basic(optional = false)
    @NotNull
    @Column(name = "Amount")
    private Double amount;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 25)
    @Column(name = "Status")
    private String status;
    @JoinColumn(name = "User_id", referencedColumnName = "id")
    @ManyToOne(optional = false, cascade = CascadeType.MERGE)
    private User userid;
    @JoinColumn(name = "Currency", referencedColumnName = "ShortName")
    @OneToOne(optional = false, cascade = CascadeType.MERGE)
    private Currency currency;

    public Systemacc() {
    }

    public Systemacc(Integer accNum) {
        this.accNum = accNum;
    }

    public Systemacc(Integer accNum, double amount, String status) {
        this.accNum = accNum;
        this.amount = amount;
        this.status = status;
    }

    public Integer getAccNum() {
        return accNum;
    }

    public void setAccNum(Integer accNum) {
        this.accNum = accNum;
    }

    public Double getAmount() {
        if (amount == null) {
            amount = 0.0;
        }
        return amount;
    }

    public void setAmount(Double amount) {
        this.amount = amount;
    }

    public String getStatus() {
        if (status == null) {
            status = "OPEN";
        }
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public User getUserid() {
        return userid;
    }

    public void setUserid(User userid) {
        this.userid = userid;
    }

    public Currency getCurrency() {
        return currency;
    }

    public void setCurrency(Currency currency) {
        this.currency = currency;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (accNum != null ? accNum.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Systemacc)) {
            return false;
        }
        Systemacc other = (Systemacc) object;
        if ((this.accNum == null && other.accNum != null) || (this.accNum != null && !this.accNum.equals(other.accNum))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.bionic.ce.entities.Systemacc[ accNum=" + accNum + " ]";
    }
}
